{extend name="adminblue/base" /}
{block name="resources"/}
<script type="text/javascript" src="ADMIN_JS/jscommon.js"></script>
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="20%" style="text-align: left;">

		</th>

		<th>
			<select id="trade_status"  class="select-common middle">
				<option value ="">全部</option>
				<option value ="0">挂买单</option>
				<option value ="1">待付款</option>
				<option value ="2">待收款</option>
				<option value ="3">已完成</option>
				<option value ="-1">已终止</option>
			</select>
			<input type="text" id ='post_user_tel' placeholder="输入买方完整手机号" class="input-common middle" />
			<input type="text" id ='op_user_tel' placeholder="输入卖方完整手机号" class="input-common middle" />
			<input type="button" onclick="searchData()" value="搜索" class="btn-common" />

		</th>
	</tr>
</table>
<table class="table-class" >
	<thead>
		<tr align="center">
			<th>ID</th>
			<th class="tal">买方</th>
			<th class="tal">卖方</th>
			<th class="tal">状态</th>
			<th>数量</th>
			<th>价格</th>
			<th>总价</th>
			<th>流水号</th>
			<th align="left">时间</th>
			<th>支付凭证</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="my-table"></tbody>
</table>


<!-- 匹配订单 -->
<div class="modal fade hide" id="match_record" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 800px">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>匹配订单</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<div>
						请选择需要匹配的首码：
						<select id="op_uid">
							<option value="-1">请选择匹配用户</option>
							{foreach name="user_list" item="vo"}
							<option value="{$vo.uid}">{$vo.real_name}</option>
							{/foreach}
						</select>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<input type="hidden" id="point_id" />
				<button class="btn btn-primary" onclick="act_match_record()">匹配</button>
				<button class="btn" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	<input id="fid" type="hidden">
</div>

{/block}
{block name="script"}
<script type="text/javascript">
    function LoadingInfo(page_index) {
        var post_user_tel = $("#post_user_tel").val();
        var op_user_tel = $("#op_user_tel").val();
        var trade_status = $("#trade_status").val();
        $.ajax({
            type : "post",
            url : document.location,
            data : {
                "page_index" : page_index,
                "page_size" : $("#showNumber").val(),
				"trade_status" :trade_status,
				"post_user_tel" :post_user_tel,
				"op_user_tel":op_user_tel
            },
            success : function(data) {
                if (data["data"].length > 0) {
                    $("#my-table").empty();
                    for (var i = 0; i < data["data"].length; i++) {
                        var html = '';
                        html += '<tr align="center">';
                        html += '<td class="tal">'+ data["data"][i]["fid"] +'</td>'
                        html += '<td class="tal">'+ data["data"][i]["real_name"] +'<br>'+ data["data"][i]["user_tel"] +'</td>'
                        html += '<td class="tal">'+ data["data"][i]["op_real_name"] +'<br>'+ data["data"][i]["op_user_tel"] +'</td>'
                        html += '<td class="tal">';
                        if(data["data"][i]["trade_status"]===0)
                        {
                            html += '挂单';
                        }
                        else if(data["data"][i]["trade_status"]===1)
                        {
                            html += '<font color="red">待付款</font>';
                        }
                        else if(data["data"][i]["trade_status"]===2)
                        {
                            html += '<font color="red">待收款</font>';
                        }
                        else if(data["data"][i]["trade_status"]===3)
                        {
                            html += '<font color="green">已完成</font>';
                        }
                        else if(data["data"][i]["trade_status"]===-1)
                        {
                            html += '<font color="red">已终止</font>';
                        }
                        else
                        {
                            html += '<font color="red">已取消</font>';
                        }
                        html += '</td>';

                        html += '<td class="tal">'+data["data"][i]["coin_count"]+'</td>';
                        html += '<td class="tal">'+data["data"][i]["coin_price"]+'</td>';
                        html += '<td class="tal">'+data["data"][i]["total_price"]+'</td>';
                        html += '<td class="tal">'+data["data"][i]["trade_no"]+'</td>';
                        html += '<td class="tal"  align="left">挂单：'+timeStampTurnTime(data["data"][i]["add_time"])+'<br>匹配：'+timeStampTurnTime(data["data"][i]["trade_time"])+'<br>支付：'+timeStampTurnTime(data["data"][i]["pay_time"])+'<br>收款：'+timeStampTurnTime(data["data"][i]["finish_time"])+'</td>';

						if(data["data"][i]["pay_pic"]) {
                            html += '<td class="tal"><a href="/'+data["data"][i]["pay_pic"]+'" target=_blank><img src="/'+data["data"][i]["pay_pic"]+'" style="height: 100px"></a></td>';
                        }
                        else{
                            html += '<td class="tal">尚未上传</td>';
						}
                        if(data["data"][i]["trade_status"] == 2) {
                            html += '<td class="tal"><a onclick="delete_record(' + data["data"][i]["tid"] + ',1)">传假图</a>' +
                                '<a onclick="rec_record(' + data["data"][i]["fid"] + ')">收款</a>' +
								'</td>';
                        }
                        else if(data["data"][i]["trade_status"] == 0)
						{
                                html += '<td class="tal">' +
									'<a onclick="delete_record(' + data["data"][i]["fid"] + ')">删除</a>' +
                                    '<a onclick="match_record(' + data["data"][i]["fid"] + ')">匹配</a>' +
									'</td>';
                        }
                        else
						{
                            html += '<td class="tal">' +
                                '<a onclick="delete_record(' + data["data"][i]["fid"] + ')">删除</a>' +
                                '</td>';
						}
                        html += '</tr>';
                        $("#my-table").append(html);
                    }
                } else {
                    var html = '<tr align="center"><td colspan="10">暂无符合条件的数据记录</td></tr>';
                    $("#my-table").html(html);
                }
                initPageData(data["page_count"],data['data'].length,data['total_count']);
                $("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
            }
        });
    }
    //搜索
    function searchData(){
        LoadingInfo(1);
    }


    // 确认收款
	function rec_record(fid) {
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $.ajax({
                        type : "post",
                        url : "{:__URL('ADMIN_MAIN/Mine/recFundTrade')}",
                        data : {
                            "fid" : fid
                        },
                        dataType : "json",
                        success : function(data) {
                            showTip(data["message"],'success');
                        }
                    });
                    $(this).dialog('close');
                    window.location.reload();
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                },
            },
            contentText:"确定要处理这条收款记录吗？",
        });
    }


    // 删除记录
    function delete_record(fid){
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $.ajax({
                        type : "post",
                        url : "{:__URL('ADMIN_MAIN/Mine/deleteFundTrade')}",
                        data : {
                            "tid" : fid
						},
                        dataType : "json",
                        success : function(data) {
                            showTip(data["message"],'success');
                        }
                    });
                    $(this).dialog('close');
                    window.location.reload();
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                },
            },
            contentText:"确定要处理这条记录吗？",
        });
    }

    // 弹出匹配详情页面
    function match_record(fid){
        var fid = parseInt(fid);
        $("#match_record").modal("show");
        $("#fid").val(fid)
    }

    // 匹配订单
	function act_match_record() {
        var op_uid = $("#op_uid").val();
        var fid = $("#fid").val();
        if (op_uid == -1) {
            showTip('请选择匹配的用户','warning');
            return;
        }
        //alert(fid);
        var remark = $("#remark").val();
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/Mine/saveMatchFund')}",
            data : {
                "fid" : fid,
                'op_uid' :op_uid
            },
            success : function(data) {
                showTip('匹配成功！','success');
                window.location.reload();
            }
        });
    }
</script>
{/block}